package com.luboyan.CBillbill.service.user.auth.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luboyan.CBillbill.mapper.user.auth.AuthRoleMapper;
import com.luboyan.CBillbill.dao.user.auth.AuthRole;
import com.luboyan.CBillbill.dao.user.auth.AuthRoleElementOperation;
import com.luboyan.CBillbill.dao.user.auth.AuthRoleMenu;
import com.luboyan.CBillbill.service.user.auth.AuthRoleElementOperationService;
import com.luboyan.CBillbill.service.user.auth.AuthRoleMenuService;
import com.luboyan.CBillbill.service.user.auth.AuthRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 查询角色所对应的所有不同中权限业务逻辑
 */
@Service
public class AuthRoleServiceImpl implements AuthRoleService {

    //页面元素权限
    @Autowired
    private AuthRoleElementOperationService authRoleElementOperationService;

    //页面访问权限
    @Autowired
    private AuthRoleMenuService authRoleMenuService;

    @Autowired
    private AuthRoleMapper authRoleMapper;

    /**
     * 通过code获取角色
     */
    @Override
    public AuthRole getRoleByCode(String code) {
        return authRoleMapper
                .selectOne(new QueryWrapper<AuthRole>().eq("code", code));
    }

    /**
     * 查询角色所对应的页面元素权限
     */
    @Override
    public List<AuthRoleElementOperation> getRoleElementOperationsByRoleIds(Set<Long> roleIdS) {

        return authRoleElementOperationService.getRoleElementOperationsByRoleIds(roleIdS);
    }

    /**
     * 查询角色所对应的页面访问权限
     */
    @Override
    public List<AuthRoleMenu> getRoleMenusByRoleIds(Set<Long> roleIdS) {
        return authRoleMenuService.getRoleMenusByRoleIds(roleIdS);
    }
}
